package com.itheima.homework03;

import java.io.BufferedWriter;
import java.io.FileWriter;

public class XmlDemo01 {
    public static void main(String[] args) {
        // 1、使用一个StringBuilder对象来拼接XML格式的数据。
        StringBuilder sb = new StringBuilder();
        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n");
        sb.append("<books>\r\n");

        sb.append("\t<book>\r\n");
        sb.append("\t\t<name>").append("《架构师成长之路》").append("</name>\r\n");
        sb.append("\t\t<publishingHouse>").append("黑马程序员").append("</publishingHouse>\r\n");
        sb.append("\t\t<dateOfPublication>").append("2010-6-6").append("</dateOfPublication>\r\n");
        sb.append("\t\t<price>").append(125.00).append("</price>\r\n");
        sb.append("\t</book>\r\n");

        sb.append("\t<book>\r\n");
        sb.append("\t\t<name>").append("《JavaEE企业级开发》").append("</name>\r\n");
        sb.append("\t\t<publishingHouse>").append("黑马研究院").append("</publishingHouse>\r\n");
        sb.append("\t\t<dateOfPublication>").append("2011-5-5").append("</dateOfPublication>\r\n");
        sb.append("\t\t<price>").append(115.80).append("</price>\r\n");
        sb.append("\t</book>\r\n");

        sb.append("\t<book>\r\n");
        sb.append("\t\t<name>").append("《Oracle指南》").append("</name>\r\n");
        sb.append("\t\t<publishingHouse>").append("清华计算机").append("</publishingHouse>\r\n");
        sb.append("\t\t<dateOfPublication>").append("2012-7-7").append("</dateOfPublication>\r\n");
        sb.append("\t\t<price>").append(89.00).append("</price>\r\n");
        sb.append("\t</book>\r\n");
        sb.append("</books>");
        try (
                BufferedWriter bw = new BufferedWriter(new FileWriter("books.xml"));
        ){
            bw.write(sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
